package com.kun.framework.queue.dto;

import cn.hutool.core.util.RandomUtil;
import com.kun.framework.core.util.JacksonUtil;

import java.io.Serializable;

/**
 * 坤坤队列消息类
 *
 * @author gzc
 * @since 2024/8/21
 **/
public class KunMessage<V> implements Serializable {

    private String id;

    private V message;

    private MessageTypeEnum messageTypeEnum;

    public KunMessage(V message, MessageTypeEnum messageTypeEnum) {
        this.id = RandomUtil.randomNumbers(5);
        this.message = message;
        this.messageTypeEnum = messageTypeEnum;
    }

    public KunMessage(String id, V message) {
        this.id = id;
        this.message = message;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public V getMessage() {
        return message;
    }

    public void setMessage(V message) {
        this.message = message;
    }

    public MessageTypeEnum getMessageTypeEnum() {
        return messageTypeEnum;
    }

    public void setMessageTypeEnum(MessageTypeEnum messageTypeEnum) {
        this.messageTypeEnum = messageTypeEnum;
    }

    public static <V> KunMessage<V> create(V message, MessageTypeEnum messageTypeEnum) {
        return new KunMessage<>(message, messageTypeEnum);
    }

    @Override
    public String toString() {
        return JacksonUtil.toJsonStr(this);
    }

    public enum MessageTypeEnum {
        DELETE_RECORD,
        COLLECT_RECORD;

        @Override
        public String toString() {
            return this.name();
        }
    }
}
